package com.hxd.otc.module.home.model;

import com.hxd.otc.api.IMessageApi;
import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.my.bean.BaseListBean;
import com.hxd.otc.module.my.bean.MessageBean;
import com.hxd.otc.net.BaseObserver;
import com.hxd.otc.net.RetrofitManager;
import com.uber.autodispose.AutoDisposeConverter;

import io.reactivex.android.schedulers.AndroidSchedulers;

/**
 * Created by lzy on 2019/1/17 0017.
 * description ${消息Model}
 */
public class MessageModel {
    private MessageModel() {
    }

    private static class SingletonHolder {
        private static final MessageModel instance = new MessageModel();
    }

    public static MessageModel getInstance() {
        return MessageModel.SingletonHolder.instance;
    }

    /**
     * 消息列表
     *
     * @param currentPage 当前页
     * @param showCount   每页数量
     */
    public void getMessageList(int currentPage, int showCount, BaseObserver<BaseListBean<MessageBean>> observer, AutoDisposeConverter<BaseBean<BaseListBean<MessageBean>>> converter) {
        getMessageApi().getMessageList(currentPage, showCount)
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * 未读消息条数
     */
    public void getMessageNoReadCount(BaseObserver<Integer> observer, AutoDisposeConverter<BaseBean<Integer>> converter) {
        getMessageApi().getMessageNoReadCount()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    /**
     * @return 更新消息状态，标记所有为已读
     */
    public void updateMessageStatus(BaseObserver<String> observer, AutoDisposeConverter<BaseBean<String>> converter) {
        getMessageApi().updateMessageStatus()
                .observeOn(AndroidSchedulers.mainThread())
                .as(converter)
                .subscribe(observer);
    }

    private IMessageApi getMessageApi() {
        return RetrofitManager.getDefault().create(IMessageApi.class);
    }

}
